﻿using System.Diagnostics;

namespace DimensionsHelper.LanguageService.Syntax;

// Section label
//   statements
// End Section
public class SectionStatement : BodiedStatement, IDeclaration
{
    private readonly SyntaxToken _sectionKeywordToken;
    private Identifier _name;


    internal SectionStatement(SyntaxToken sectionKeywordToken, SyntaxNode? parent) :
        base(SyntaxKinds.SectionStatement, parent)
    {
        SetChildField(ref _sectionKeywordToken, sectionKeywordToken);
        _name = Identifier.Default;
    }


    public ITextNode DeclareKeywordToken => _sectionKeywordToken;

    public ITextNode NameIdentifier => _name;

    public string Name => _name.Value;


    public bool IsSignature => false;

    public bool IsTypeSignature => false;

    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        Accept(visitor, DeclareKeywordToken, NameIdentifier);
        base.AcceptVisitor(visitor);
    }

    public bool ContainsModifier(SyntaxKinds modifierKind)
    {
        return false;
    }

    public bool ContainsAnyModifier(params SyntaxKinds[] modifiersKinds)
    {
        return false;
    }


    public void Update(Identifier name)
    {
        SetChildField(ref _name, Identifier.IsDefaultOrEmpty, name);
    }
}


public static partial class NodeFactory
{
    public static SectionStatement CreateSectionStatement(SyntaxNode? parent,
        SyntaxToken sectionKeywordToken, Identifier? label)
    {
        Debug.Assert(sectionKeywordToken.IsNode(SyntaxKinds.SectionKeywordToken));
        SectionStatement section = new(sectionKeywordToken, parent);
        if (label != null)
        {
            section.Update(label);
        }

        return section;
    }
}